#include "utils.h"
#include <QFile>
#include <QTime>

#define LOG_FILE_NAME "QCamRec.log"

void resetLogFile(){
    QFile outFile(LOG_FILE_NAME);
    outFile.open(QIODevice::WriteOnly);
    outFile.close();
}
//================================================
void fileMessageHandler(QtMsgType type,
                     const QMessageLogContext &context,
                     const QString &msg){
    QString txt;
    QTime time = QTime::currentTime();
    QString timeString = time.toString();
    switch (type) {
    case QtDebugMsg:
        txt += "Debug: " + timeString + ": " + msg;
        break;
    case QtWarningMsg:
        txt += "Wàrning: " + timeString + ": " + msg;
    break;
    case QtCriticalMsg:
        txt += "ritical: " + timeString + ": " + msg;
    break;
    case QtFatalMsg:
        txt += "Debug: " + timeString + ": " + msg;
        abort();
    }
    QFile outFile(LOG_FILE_NAME);
    outFile.open(QIODevice::WriteOnly | QIODevice::Append);
    QTextStream ts(&outFile);
    ts << txt << endl;
    outFile.close();
}
